home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / calc1 / calc.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1995-05-07  |  18.0 KB  |  544 lines

  1. VERSION 2.00
  2. Begin Form Calculator 
  3.    BorderStyle     =   0  'None
  4.    Caption         =   "Calculator"
  5.    ClientHeight    =   3720
  6.    ClientLeft      =   2070
  7.    ClientTop       =   3015
  8.    ClientWidth     =   3660
  9.    ClipControls    =   0   'False
  10.    FontBold        =   -1  'True
  11.    FontItalic      =   0   'False
  12.    FontName        =   "System"
  13.    FontSize        =   9.75
  14.    FontStrikethru  =   0   'False
  15.    FontUnderline   =   0   'False
  16.    Height          =   4125
  17.    Icon            =   CALC.FRX:0000
  18.    Left            =   2010
  19.    LinkMode        =   1  'Source
  20.    LinkTopic       =   "Form1"
  21.    MaxButton       =   0   'False
  22.    ScaleHeight     =   3720
  23.    ScaleWidth      =   3660
  24.    Top             =   2670
  25.    Width           =   3780
  26.    Begin PictureBox picShade 
  27.       AutoSize        =   -1  'True
  28.       BorderStyle     =   0  'None
  29.       Height          =   120
  30.       Left            =   0
  31.       Picture         =   CALC.FRX:0302
  32.       ScaleHeight     =   120
  33.       ScaleWidth      =   120
  34.       TabIndex        =   22
  35.       Top             =   0
  36.       Visible         =   0   'False
  37.       Width           =   120
  38.    End
  39.    Begin PictureBox Gadget 
  40.       BackColor       =   &H00C0C0C0&
  41.       BorderStyle     =   0  'None
  42.       Height          =   3390
  43.       Left            =   240
  44.       ScaleHeight     =   3390
  45.       ScaleWidth      =   3255
  46.       TabIndex        =   0
  47.       Top             =   240
  48.       Width           =   3255
  49.       Begin SSPanel Panel3D1 
  50.          BackColor       =   &H00C0C0C0&
  51.          Caption         =   "Panel3D1"
  52.          Font3D          =   3  'Inset w/light shading
  53.          ForeColor       =   &H00800000&
  54.          Height          =   285
  55.          Left            =   120
  56.          TabIndex        =   23
  57.          Top             =   90
  58.          Width           =   3030
  59.          Begin PictureBox Picture1 
  60.             BackColor       =   &H00C0C0C0&
  61.             BorderStyle     =   0  'None
  62.             Height          =   255
  63.             Left            =   15
  64.             ScaleHeight     =   255
  65.             ScaleWidth      =   3000
  66.             TabIndex        =   24
  67.             Top             =   15
  68.             Width           =   3000
  69.          End
  70.       End
  71.       Begin SSCommand Command3D1 
  72.          Caption         =   "OFF"
  73.          Font3D          =   0  'None
  74.          ForeColor       =   &H000000FF&
  75.          Height          =   375
  76.          Left            =   120
  77.          TabIndex        =   21
  78.          Top             =   480
  79.          Width           =   615
  80.       End
  81.       Begin CommandButton Percent 
  82.          Caption         =   "%"
  83.          FontBold        =   -1  'True
  84.          FontItalic      =   0   'False
  85.          FontName        =   "System"
  86.          FontSize        =   9.75
  87.          FontStrikethru  =   0   'False
  88.          FontUnderline   =   0   'False
  89.          Height          =   480
  90.          Left            =   2640
  91.          TabIndex        =   19
  92.          Top             =   2760
  93.          Width           =   480
  94.       End
  95.       Begin CommandButton Operator 
  96.          Caption         =   "="
  97.          FontBold        =   -1  'True
  98.          FontItalic      =   0   'False
  99.          FontName        =   "System"
  100.          FontSize        =   9.75
  101.          FontStrikethru  =   0   'False
  102.          FontUnderline   =   0   'False
  103.          Height          =   480
  104.          Index           =   4
  105.          Left            =   2040
  106.          TabIndex        =   18
  107.          Top             =   2760
  108.          Width           =   480
  109.       End
  110.       Begin CommandButton Decimal 
  111.          Caption         =   "."
  112.          FontBold        =   -1  'True
  113.          FontItalic      =   0   'False
  114.          FontName        =   "System"
  115.          FontSize        =   9.75
  116.          FontStrikethru  =   0   'False
  117.          FontUnderline   =   0   'False
  118.          Height          =   480
  119.          Left            =   1320
  120.          TabIndex        =   17
  121.          Top             =   2760
  122.          Width           =   480
  123.       End
  124.       Begin CommandButton Number 
  125.          Caption         =   "0"
  126.          FontBold        =   -1  'True
  127.          FontItalic      =   0   'False
  128.          FontName        =   "System"
  129.          FontSize        =   9.75
  130.          FontStrikethru  =   0   'False
  131.          FontUnderline   =   0   'False
  132.          Height          =   480
  133.          Index           =   0
  134.          Left            =   120
  135.          TabIndex        =   16
  136.          Top             =   2760
  137.          Width           =   1080
  138.       End
  139.       Begin CommandButton Operator 
  140.          Caption         =   "/"
  141.          FontBold        =   -1  'True
  142.          FontItalic      =   0   'False
  143.          FontName        =   "System"
  144.          FontSize        =   9.75
  145.          FontStrikethru  =   0   'False
  146.          FontUnderline   =   0   'False
  147.          Height          =   480
  148.          Index           =   0
  149.          Left            =   2640
  150.          TabIndex        =   15
  151.          Top             =   2160
  152.          Width           =   480
  153.       End
  154.       Begin CommandButton Operator 
  155.          Caption         =   "X"
  156.          FontBold        =   -1  'True
  157.          FontItalic      =   0   'False
  158.          FontName        =   "System"
  159.          FontSize        =   9.75
  160.          FontStrikethru  =   0   'False
  161.          FontUnderline   =   0   'False
  162.          Height          =   480
  163.          Index           =   2
  164.          Left            =   2040
  165.          TabIndex        =   14
  166.          Top             =   2160
  167.          Width           =   480
  168.       End
  169.       Begin CommandButton Number 
  170.          Caption         =   "3"
  171.          FontBold        =   -1  'True
  172.          FontItalic      =   0   'False
  173.          FontName        =   "System"
  174.          FontSize        =   9.75
  175.          FontStrikethru  =   0   'False
  176.          FontUnderline   =   0   'False
  177.          Height          =   480
  178.          Index           =   3
  179.          Left            =   1320
  180.          TabIndex        =   13
  181.          Top             =   2160
  182.          Width           =   480
  183.       End
  184.       Begin CommandButton Number 
  185.          Caption         =   "2"
  186.          FontBold        =   -1  'True
  187.          FontItalic      =   0   'False
  188.          FontName        =   "System"
  189.          FontSize        =   9.75
  190.          FontStrikethru  =   0   'False
  191.          FontUnderline   =   0   'False
  192.          Height          =   480
  193.          Index           =   2
  194.          Left            =   720
  195.          TabIndex        =   12
  196.          Top             =   2160
  197.          Width           =   480
  198.       End
  199.       Begin CommandButton Number 
  200.          Caption         =   "1"
  201.          FontBold        =   -1  'True
  202.          FontItalic      =   0   'False
  203.          FontName        =   "System"
  204.          FontSize        =   9.75
  205.          FontStrikethru  =   0   'False
  206.          FontUnderline   =   0   'False
  207.          Height          =   480
  208.          Index           =   1
  209.          Left            =   120
  210.          TabIndex        =   11
  211.          Top             =   2160
  212.          Width           =   480
  213.       End
  214.       Begin CommandButton Operator 
  215.          Caption         =   "-"
  216.          FontBold        =   -1  'True
  217.          FontItalic      =   0   'False
  218.          FontName        =   "System"
  219.          FontSize        =   9.75
  220.          FontStrikethru  =   0   'False
  221.          FontUnderline   =   0   'False
  222.          Height          =   480
  223.          Index           =   3
  224.          Left            =   2640
  225.          TabIndex        =   10
  226.          Top             =   1560
  227.          Width           =   480
  228.       End
  229.       Begin CommandButton Operator 
  230.          Caption         =   "+"
  231.          FontBold        =   -1  'True
  232.          FontItalic      =   0   'False
  233.          FontName        =   "System"
  234.          FontSize        =   9.75
  235.          FontStrikethru  =   0   'False
  236.          FontUnderline   =   0   'False
  237.          Height          =   480
  238.          Index           =   1
  239.          Left            =   2040
  240.          TabIndex        =   9
  241.          Top             =   1560
  242.          Width           =   480
  243.       End
  244.       Begin CommandButton Number 
  245.          Caption         =   "6"
  246.          FontBold        =   -1  'True
  247.          FontItalic      =   0   'False
  248.          FontName        =   "System"
  249.          FontSize        =   9.75
  250.          FontStrikethru  =   0   'False
  251.          FontUnderline   =   0   'False
  252.          Height          =   480
  253.          Index           =   6
  254.          Left            =   1320
  255.          TabIndex        =   8
  256.          Top             =   1560
  257.          Width           =   480
  258.       End
  259.       Begin CommandButton Number 
  260.          Caption         =   "5"
  261.          FontBold        =   -1  'True
  262.          FontItalic      =   0   'False
  263.          FontName        =   "System"
  264.          FontSize        =   9.75
  265.          FontStrikethru  =   0   'False
  266.          FontUnderline   =   0   'False
  267.          Height          =   480
  268.          Index           =   5
  269.          Left            =   720
  270.          TabIndex        =   7
  271.          Top             =   1560
  272.          Width           =   480
  273.       End
  274.       Begin CommandButton Number 
  275.          Caption         =   "4"
  276.          FontBold        =   -1  'True
  277.          FontItalic      =   0   'False
  278.          FontName        =   "System"
  279.          FontSize        =   9.75
  280.          FontStrikethru  =   0   'False
  281.          FontUnderline   =   0   'False
  282.          Height          =   480
  283.          Index           =   4
  284.          Left            =   120
  285.          TabIndex        =   6
  286.          Top             =   1560
  287.          Width           =   480
  288.       End
  289.       Begin CommandButton CancelEntry 
  290.          Caption         =   "CE"
  291.          FontBold        =   -1  'True
  292.          FontItalic      =   0   'False
  293.          FontName        =   "System"
  294.          FontSize        =   9.75
  295.          FontStrikethru  =   0   'False
  296.          FontUnderline   =   0   'False
  297.          Height          =   480
  298.          Left            =   2640
  299.          TabIndex        =   5
  300.          Top             =   960
  301.          Width           =   480
  302.       End
  303.       Begin CommandButton Cancel 
  304.          Caption         =   "C"
  305.          FontBold        =   -1  'True
  306.          FontItalic      =   0   'False
  307.          FontName        =   "System"
  308.          FontSize        =   9.75
  309.          FontStrikethru  =   0   'False
  310.          FontUnderline   =   0   'False
  311.          Height          =   480
  312.          Left            =   2040
  313.          TabIndex        =   4
  314.          Top             =   960
  315.          Width           =   480
  316.       End
  317.       Begin CommandButton Number 
  318.          Caption         =   "9"
  319.          FontBold        =   -1  'True
  320.          FontItalic      =   0   'False
  321.          FontName        =   "System"
  322.          FontSize        =   9.75
  323.          FontStrikethru  =   0   'False
  324.          FontUnderline   =   0   'False
  325.          Height          =   480
  326.          Index           =   9
  327.          Left            =   1320
  328.          TabIndex        =   3
  329.          Top             =   960
  330.          Width           =   480
  331.       End
  332.       Begin CommandButton Number 
  333.          Caption         =   "8"
  334.          FontBold        =   -1  'True
  335.          FontItalic      =   0   'False
  336.          FontName        =   "System"
  337.          FontSize        =   9.75
  338.          FontStrikethru  =   0   'False
  339.          FontUnderline   =   0   'False
  340.          Height          =   480
  341.          Index           =   8
  342.          Left            =   720
  343.          TabIndex        =   2
  344.          Top             =   960
  345.          Width           =   480
  346.       End
  347.       Begin CommandButton Number 
  348.          Caption         =   "7"
  349.          FontBold        =   -1  'True
  350.          FontItalic      =   0   'False
  351.          FontName        =   "System"
  352.          FontSize        =   9.75
  353.          FontStrikethru  =   0   'False
  354.          FontUnderline   =   0   'False
  355.          Height          =   480
  356.          Index           =   7
  357.          Left            =   120
  358.          TabIndex        =   1
  359.          Top             =   960
  360.          Width           =   480
  361.       End
  362.       Begin Label Readout 
  363.          Alignment       =   1  'Right Justify
  364.          BackColor       =   &H0000FFFF&
  365.          BorderStyle     =   1  'Fixed Single
  366.          Caption         =   "0."
  367.          FontBold        =   -1  'True
  368.          FontItalic      =   0   'False
  369.          FontName        =   "MS Sans Serif"
  370.          FontSize        =   12
  371.          FontStrikethru  =   0   'False
  372.          FontUnderline   =   0   'False
  373.          ForeColor       =   &H00000000&
  374.          Height          =   375
  375.          Left            =   840
  376.          TabIndex        =   20
  377.          Top             =   480
  378.          Width           =   2280
  379.       End
  380.    End
  381. ' ------------------------------------------------------------------------
  382. '               Copyright (C) 1991 Microsoft Corporation
  383. ' You have a royalty-free right to use, modify, reproduce and distribute
  384. ' the Sample Application Files (and/or any modified version) in any way
  385. ' you find useful, provided that you agree that Microsoft has no warranty,
  386. ' obligations or liability for any Sample Application Files.
  387. ' ------------------------------------------------------------------------
  388. Option Explicit
  389. Dim Op1, Op2                ' Previously input operand.
  390. Dim DecimalFlag As Integer  ' Decimal point present yet?
  391. Dim NumOps As Integer       ' Number of operands.
  392. Dim LastInput               ' Indicate type of last keypress.
  393. Dim OpFlag                  ' Indicate pending operation.
  394. Dim TempReadout
  395. ' Click event procedure for C (cancel) key.
  396. ' Reset the display and initializes variables.
  397. Sub Cancel_Click ()
  398.     ReadOut = "0."
  399.     Op1 = 0
  400.     Op2 = 0
  401.     Form_Load
  402. End Sub
  403. ' Click event procedure for CE (cancel entry) key.
  404. Sub CancelEntry_Click ()
  405.     ReadOut = "0."
  406.     DecimalFlag = False
  407.     LastInput = "CE"
  408. End Sub
  409. Sub Command3D1_Click ()
  410.     Unload Calculator
  411. End Sub
  412. ' Click event procedure for decimal point (.) key.
  413. ' If last keypress was an operator, initialize
  414. ' readout to "0." Otherwise, append a decimal
  415. ' point to the display.
  416. Sub Decimal_Click ()
  417.     If LastInput = "NEG" Then
  418.     ReadOut = "-0."
  419.     ElseIf LastInput <> "NUMS" Then
  420.     ReadOut = "0."
  421.     End If
  422.     DecimalFlag = True
  423.     LastInput = "NUMS"
  424. End Sub
  425. ' Initialization routine for the form.
  426. ' Set all variables to initial values.
  427. Sub Form_Load ()
  428.     DecimalFlag = False
  429.     NumOps = 0
  430.     LastInput = "NONE"
  431.     OpFlag = " "
  432.     Call AllignForm(Calculator)
  433. End Sub
  434. Sub Form_Paint ()
  435.     Make3DForm Calculator, Gadget
  436. End Sub
  437. Sub Form_Unload (Cancel As Integer)
  438.     Dim res As Integer
  439. End Sub
  440. ' Click event procedure for number keys (0-9).
  441. ' Appends new number to the number in the display.
  442. Sub Number_Click (Index As Integer)
  443.     If LastInput <> "NUMS" Then
  444.     ReadOut = "."
  445.     DecimalFlag = False
  446.     End If
  447.     If DecimalFlag Then
  448.     ReadOut = ReadOut + Number(Index).Caption
  449.     Else
  450.     ReadOut = Left(ReadOut, InStr(ReadOut, ".") - 1) + Number(Index).Caption + "."
  451.     End If
  452.     If LastInput = "NEG" Then ReadOut = "-" & ReadOut
  453.     LastInput = "NUMS"
  454. End Sub
  455. ' Click event procedure for operator keys (+, -, x, /, =).
  456. ' If the immediately preceeding keypress was part of a
  457. ' number, increment NumOps. If one operand is present,
  458. ' set Op1. If two are present, set Op1 equal to the
  459. ' result of the operation on Op1 and the current
  460. ' input string, and display the result.
  461. Sub Operator_Click (Index As Integer)
  462.     TempReadout = ReadOut
  463.     If LastInput = "NUMS" Then
  464.     NumOps = NumOps + 1
  465.     End If
  466.     Select Case NumOps
  467.     Case 0
  468.     If Operator(Index).Caption = "-" And LastInput <> "NEG" Then
  469.         ReadOut = "-" & ReadOut
  470.         LastInput = "NEG"
  471.     End If
  472.     Case 1
  473.     Op1 = ReadOut
  474.     If Operator(Index).Caption = "-" And LastInput <> "NUMS" And OpFlag <> "=" Then
  475.         ReadOut = "-"
  476.         LastInput = "NEG"
  477.     End If
  478.     Case 2
  479.     Op2 = TempReadout
  480.     Select Case OpFlag
  481.         Case "+"
  482.         Op1 = Val(Op1) + Val(Op2)
  483.         Case "-"
  484.         Op1 = Op1 - Op2
  485.         Case "X"
  486.         Op1 = Op1 * Op2
  487.         Case "/"
  488.         If Op2 = 0 Then
  489.            MsgBox "Can't divide by zero", 48, "Calculator"
  490.         Else
  491.            Op1 = Op1 / Op2
  492.         End If
  493.         Case "="
  494.         Op1 = Op2
  495.         Case "%"
  496.         Op1 = Op1 * Op2
  497.         End Select
  498.     ReadOut = Op1
  499.     NumOps = 1
  500.     End Select
  501.     If LastInput <> "NEG" Then
  502.     LastInput = "OPS"
  503.     OpFlag = Operator(Index).Caption
  504.     End If
  505. End Sub
  506. ' Click event procedure for percent key (%).
  507. ' Compute and display a percentage of the first operand.
  508. Sub Percent_Click ()
  509.     ReadOut = ReadOut / 100
  510.     LastInput = "Ops"
  511.     OpFlag = "%"
  512.     NumOps = NumOps + 1
  513.     DecimalFlag = True
  514. End Sub
  515. Sub Picture1_MouseDown (Button As Integer, Shift As Integer, X As Single, Y As Single)
  516.     PixStartX = (Calculator.Left) / TPRatio
  517.     PixStartY = (Calculator.Top) / TPRatio
  518.     PixOffsetX = Int(X / TPRatio)
  519.     PixOffsetY = Int(Y / TPRatio)
  520.     OkToMove = True
  521.     GhostForm PixStartX, PixStartY, PixStartX + (Calculator.Width / TPRatio), PixStartY + (Calculator.Height / TPRatio)
  522. End Sub
  523. Sub Picture1_MouseMove (Button As Integer, Shift As Integer, X As Single, Y As Single)
  524.     If Button = 1 And OkToMove = True Then
  525.     OkToMove = False
  526.     PixX = Int(X / TPRatio) - PixOffsetX
  527.     PixY = Int(Y / TPRatio) - PixOffsetY
  528.     GhostForm PixStartX, PixStartY, PixStartX + (Calculator.Width / TPRatio), PixStartY + (Calculator.Height / TPRatio)
  529.     GhostForm PixStartX + PixX, PixStartY + PixY, PixStartX + PixX + (Calculator.Width / TPRatio), PixStartY + PixY + (Calculator.Height / TPRatio)
  530.     PixOffsetX = Int(X / TPRatio)
  531.     PixOffsetY = Int(Y / TPRatio)
  532.     PixStartX = PixStartX + PixX
  533.     PixStartY = PixStartY + PixY
  534.     OkToMove = True
  535.     End If
  536. End Sub
  537. Sub Picture1_MouseUp (Button As Integer, Shift As Integer, X As Single, Y As Single)
  538.     GhostForm PixStartX, PixStartY, PixStartX + (Calculator.Width / TPRatio), PixStartY + (Calculator.Height / TPRatio)
  539.     Calculator.Move (PixStartX) * TPRatio, (PixStartY) * TPRatio
  540. End Sub
  541. Sub Picture1_Paint ()
  542.     ShadeControl Picture1, picShade
  543. End Sub
  544.